const fs = require('fs')

exports.getMime = function(extname) {
  switch(extname) {
    case '.html': 
      return 'text/html'
    case '.css': 
      return 'text/css'
    case '.js':
      return 'text/javascript'
    defalut:
      return 'text/html'
  }
}

exports.getFileMime = function(extname) {
  const data = fs.readFileSync('./data/mime.json')
  const mimeObj = JSON.parse(data.toString())
  return mimeObj[extname]
}

exports.setRes = function(res, status, ctntype, data) {
  res.writeHead(status, {'Content-Type': `${ctntype};charset="utf-8"`});
  res.end(data);
}